package com.daydayup.learn.zikao;

import lombok.Data;

@Data
public class Rect {

    private Point p1;

    private Point p2;

    private int width;

    private int height;

    public Rect(Point p1,Point p2) {
        this.p1 = p1;
        this.p2 = p2;
        this.width = Math.abs(p1.getX() - p2.getX());
        this.height = Math.abs(p1.getY() - p2.getY());
    }

    /**
     * 获取周长
     * @return
     */
    public int getPerimeter(){
        return (width + height) * 2;
    }

    public int getArea() {
        return width * height;
    }
}
